package cn.ekuma.epos.datalogic.define.dao;

import cn.ekuma.data.dao.ModifiedLogDAO;
import cn.ekuma.epos.module.Module;

import com.openbravo.data.basic.BasicException;
import com.openbravo.data.loader.DataRead;
import com.openbravo.data.loader.DataWrite;
import com.openbravo.data.loader.Datas;
import com.openbravo.data.loader.I_Session;
import com.openbravo.data.loader.Session;
import com.openbravo.data.loader.TableDefinition;
import com.openbravo.data.model.Field;
import com.openbravo.format.Formats;

public class ModuleDAO extends ModifiedLogDAO<Module>{
	
	public ModuleDAO(I_Session s) {
		super(s);
	}

@Override
public Module readValues(DataRead dr,Module obj) throws BasicException {
	if(obj==null)
		obj=new Module();
	obj.setId(dr.getString(1));
	obj.setModuleName(dr.getString(2));
	obj.setVersion(dr.getString(3));
	obj.setMajorVersion(dr.getInt(4));
	obj.setMinorVersion(dr.getInt(5));
	return obj;
}

@Override
public TableDefinition getTable() {
	return new TableDefinition(s,
            "APPLICATIONS",
            new Field[]{
                 new Field("ID",Datas.STRING,Formats.STRING),
                 new Field("NAME",Datas.STRING,Formats.STRING),
                 new Field("VERSION",Datas.STRING,Formats.STRING),
                 new Field("MAJORVERSION",Datas.INT,Formats.INT),
                 new Field("MINORVERSION",Datas.INT,Formats.INT),
                 new Field("LASTLOGINDATE",Datas.TIMESTAMP,Formats.TIMESTAMP)
                },
            new int[]{0});
}

@Override
public void writeInsertValues(DataWrite dp, Module obj) throws BasicException {
	dp.setString(1,obj.getId());
	dp.setString(2,obj.getModuleName());
	dp.setString(3,obj.getVersion());
	dp.setInt(4,obj.getMajorVersion());
	dp.setInt(5,obj.getMinorVersion());
	dp.setTimestamp(6,obj.getLastModified());
	
}

@Override
public Class getSuportClass() {
	return Module.class;
}
}
